<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="./css/base.css" rel="stylesheet">
    <link href="./css/head.css" rel="stylesheet">
    <link href="./css/pet_kinds.css" rel="stylesheet">
</head>

<body>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/Utils.js"></script>
    <script src="js/head.js"></script>
    <script src="js/mock.js"></script>
    <script src="mock/pet.js"></script>

    <div class="head"></div>
    <div class="nav_head">
        <span>
            <a href="./index.html">首页</a>
        </span>
        <span>
            <a href="./pet_kinds.html">宠物</a>
        </span>

        <span>
            <a href="./pet_thing.html">宠物用品</a>
        </span>

        <span>
            <a href="./mine.html">个人中心</a>
        </span>
    </div>


    <div class="main">
        <div class="kind_box">
        </div>
    </div>


    <script>
        init(Mock)

        $.ajax({
            'url': baseUrl + 'pet_types.php',
            'type': 'GET',
            'success': function (res) {
                res = JSON.parse(res)
                let data = res.data

                if (res.code == 200) {
                    for (let i = 0; i < data.length; i++) {
                        $('.kind_box').append(`
                        
                            <div class="kind">
                                <img src=${baseUrl + data[i].image} />
                                <span id="type">${data[i].type}</span>
                            </div>    
                    `)
                    }

                    kindClickEve()
                }else{
                    console.log(data.msg)
                }


            }
        })

        //宠物类型点击事件
        function kindClickEve() {
            let kinds = $('.kind_box').children()

            for (let i = 0; i < kinds.length; i++) {
                kinds.eq(i).click(function () {

                    let type = kinds.eq(i).children('#type').text()
                    setSession('type', type)

                    location.href = "pets.html"

                })
            }
        }
    </script>
</body>

</html>